<script setup lang="ts">
import { Handle, Position, useVueFlow } from '@vue-flow/core'
import { computed, ref, watch } from 'vue'

defineOptions({
  name: 'HttpOutNode'
})

const props = defineProps<{
  id: string;
  data: {
    name: string;
    route?: string;
  };
  style?: Record<string, any>; // 添加 style 属性
}>()

const { updateNodeData } = useVueFlow()

const name = computed({
  get: () => props.data.name,
  set: (name) => updateNodeData(props.id, {...props.data, name: name }),
})

import useConnectionValid from './ts/connectionValid';
const { isValidConnection } = useConnectionValid();

// 节点属性
const route = ref(props.data.route || '');

watch(() => [route.value, ], ()=>{
  updateNodeData(props.id, {
    ...props.data,
    route: route.value,
  })
})

</script>

<template>
    <div class="NodeName"> <input :id="`${id}-input`" v-model="name"  class="nodrag" /> </div>
    <div class="NodeContent">
      <Handle id="flow-end" type="target" :class="['AgentFlowInputHandle','top-0']"  :position="Position.Left"  title="Flow End"  :connectable="()=>{return isValidConnection(props.id,'flow-end', 'target')}"><span class="HandleLeftSpan">Flow End</span></Handle>
      <Handle id="return-msg"  type="target" :class="['AgentMsg','top-2']" :position="Position.Left"  title="Return Message"  :connectable="()=>{return isValidConnection(props.id,'return-msg', 'target')}"><span class="HandleLeftSpan">Return Message</span></Handle>
      
      
      <div class="NodeData">
        <!-- Route input -->
        <div class="input-row">
          <label for="routeInput">Route:</label>
          <input
            id="routeInput"
            type="text"
            v-model="route"
            placeholder="/your-route"
            :class="['text-input','nodrag']"
          />
        </div>
        
      </div>
    </div>
</template>

<style scoped>
.NodeName {
  position: relative;
  display: inline-block;
  font-size: 14px;
  width: 100%;
  padding-left: 70px;
  padding-right: 70px;
  text-align: center;
}

.NodeName input {
  max-height: 20px;
  height: 100%;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: #333;
  font-size: 16px;
  padding: 8px 12px;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
  text-align: center;
  background-color: #00000000;
}

/* 输入框聚焦时 */
.NodeName input:focus {
  background-color: #f5f5f5;
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.5);
  color: #000;
}

/* 输入框没有内容时（placeholder显示） */
.NodeName input:placeholder-shown {
  color: #ffffff;
}

/* 输入框内容区域边距 */
.NodeName input::placeholder {
  color: #ccc;
  font-style: italic;
}

/* 输入框平滑过渡效果 */
.NodeName input {
  transition: background-color 0.3s, box-shadow 0.3s, color 0.3s;
}

.NodeContent{
  height: 100%;
  width: 100%;
}
</style> 